package sheji.jianZao.yuanXing;

import java.util.Random;

public class ClientDemo {
    // 发送账单的数量，这个值是从数据库中获得的
    private static final int MAX_COUNT = 6;

    public static void main(String[] args) {
        // 定义一个邮件对象
        String subject = "某商场五一抽奖活动";
        String context = "五一抽奖活动通知：凡在五一期间在本商场购物满100元的客户都有获得抽奖机会！...";
        Mail mail = new Mail(subject, context);
        mail.setTail("解释权归某商场所有");

        // 模拟发送邮件
        for (int i = 1; i < MAX_COUNT; i++) {
            // 以下是每封邮件不同的地方
            String appellation = getRandString(5) + " 先生（女士）";
            String receiver = getRandString(5) + "@" + getRandString(8) + ".com";
            //克隆邮件
            Mail cloneMail = mail.clone();
            cloneMail.setAppellation(appellation);
            cloneMail.setReceiver(receiver);
            // 发送邮件
            sendMail(cloneMail);
        }
    }

    // 发送邮件
    public static void sendMail(Mail mail) {
        System.out.println("标题：" + mail.getSubject()
                + "\t收件人：" + mail.getReceiver()
                + "\t....发送成功！");
    }

    // 获得指定长度的随机字符串
    public static String getRandString(int maxLength) {
        String source = "abcdefghijklmnopqrskuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        StringBuilder sb = new StringBuilder();
        Random rand = new Random();
        for (int i = 0; i < maxLength; i++) {
            sb.append(source.charAt(rand.nextInt(source.length())));
        }
        return sb.toString();
    }
}